package com.fhz.a1911;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

/**
 * 时间:2022/5/19
 *
 * @author msfeng
 * 简述: TODO
 */
public class MyViewModel extends ViewModel {
    private final MutableLiveData<Integer> mutableLiveDataIndex = new MutableLiveData<>();

    private int index = 0;
    public MyViewModel(int index) {
        this.index = index;
        mutableLiveDataIndex.setValue(index);
    }

    //
//    public int getIndex() {
//        return index;
//    }
//
//    public void setIndex(int index) {
//        this.index = index;
//    }

    //借助liveData.

    public void setIndex(Integer index){
//        mutableLiveDataIndex.setValue(index);
        mutableLiveDataIndex.postValue(index);
    }
    public MutableLiveData<Integer> getMutableLiveDataIndex() {
        return mutableLiveDataIndex;
    }



    //借助liveData.
    private final MutableLiveData<String> mutableLiveData = new MutableLiveData<>();

    public void setString(String s){
        mutableLiveData.postValue(s);
    }

    public MutableLiveData<String> getMutableLiveData() {
        return mutableLiveData;
    }
}

